home *** CD-ROM | disk | FTP | other *** search
/ MaxiMac 2001 May / MaxiMac 114.iso / Macworld on CD n°114 / Macworld Pratiques / Programmation / Pour AppleScript / Desktop Auto-Rebuilder / Desktop Auto-Rebuilder.src < prev    next >
Encoding:
Text File  |  1998-12-02  |  2.9 KB  |  98 lines  |  [TEXT/ToyS]

  1. -- Activate the Finder so it can do all the work.
  2. tell application "Finder"
  3.     activate
  4.     
  5.     -- First we'll make sure that Jon's Commands is actually in the Scripting Additions folder.
  6.     -- We'll put the path to the System folder in a variable called sysPath.
  7.     
  8.     path to system folder
  9.     set sysPath to the result
  10.     
  11.     set jonAvail to "false"
  12.     
  13.     -- Next we'll look in the Scripting Additions folder, inside the Extensions folder.
  14.     try
  15.         select file "Jon’s Commands" of folder "Scripting Additions" of folder "Extensions" of sysPath
  16.         set jonAvail to "true"
  17.     on error
  18.         set jonAvail to "false"
  19.     end try
  20.     
  21.     -- Next we'll look in the Scripting Additions folder, System Folder.
  22.     
  23.     if jonAvail = "false" then
  24.         try
  25.             select file "Jon’s Commands" of folder "Scripting Additions" of sysPath
  26.             set jonAvail to "true"
  27.         on error
  28.             set jonAvail to "false"
  29.         end try
  30.     end if
  31.     
  32.     -- Now we'll inform the user if they don't have it available.
  33.     if jonAvail = "false" then
  34.         display dialog ¬
  35.             "Could not find Jon's Commands in the Scripting Additions folder. Please put it there and restart your computer to use this applet." buttons {"Ok"} default button 1 ¬
  36.             giving up after 30
  37.         
  38.         return
  39.     end if
  40.     
  41.     -- Now Jon's Commands does the work of erasing the Desktop DB & DF files.
  42.     try
  43.         set the diskName to the name of the startup disk
  44.         {diskName, ":Trash:"} as string
  45.         
  46.         -- I left the result commands in as a debugging function. Makes no difference tot he end user.
  47.         result
  48.         set the trashPath to the result
  49.         
  50.         {diskName, ":Desktop DB"} as string
  51.         result
  52.         set dbPath to the result
  53.         
  54.         {diskName, ":Desktop DF"} as string
  55.         result
  56.         set dfPath to the result
  57.         
  58.         moveFile alias dbPath to alias trashPath
  59.         moveFile alias dfPath to alias trashPath
  60.         
  61.         -- Display a dialog box informing the user that an error has occurred. This is a timed dialog box which will go away after 20 seconds.
  62.         display dialog ¬
  63.             "The Desktop DB and Desktop DF files were successfully moved to the trash. You should now restart your computer." buttons {"Restart", "Shutdown", "Continue"} default button 3 ¬
  64.             giving up after 30
  65.         
  66.         -- Put the results of the button push in a variable called button_pressed
  67.         set the button_pressed to the button returned of the result
  68.         
  69.         -- If restart
  70.         if the button_pressed is "Restart" then
  71.             restart
  72.         end if
  73.         
  74.         -- If shutdown
  75.         if the button_pressed is "Shutdown" then
  76.             shutdown
  77.         end if
  78.         
  79.         -- If continue
  80.         if the button_pressed is "Continue" then
  81.             return
  82.         end if
  83.         
  84.     on error    
  85.     
  86.         -- Display a dialog box informing the user that an error has occurred. This is a timed dialog box which will go away after 20 seconds.
  87.         display dialog ¬
  88.             "Oops! Desktop Purger couldn't move the Desktop DB and Desktop DF files to the trash. They may already be in the trash. Also, make sure you restarted your Macintosh after putting the Jon's Commands in the Scripting Additions folder." buttons {"Ok"} default button 1 ¬
  89.             giving up after 20
  90.             
  91.             
  92.         
  93.     end try
  94.     
  95.     return
  96.     
  97. end tell
  98.